package cn.com.se.多线程.excel;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.poifs.filesystem.Entry;

import java.security.SecureRandom;
import java.util.*;

/**
 * @Description TODO
 * @Author:lingheng
 * @Date:2022-10-24 10:01
 * @Version 1.0
 **/
public class Test1 {


    public static Map<String, String> initMap = new HashMap<>();

    public static void main(String[] args) {
        ExcelReader reader = ExcelUtil.getReader("D:/data.xlsx");
        List<Map<String, Object>> readAll = reader.readAll();
        List<String> list = new ArrayList<>();
        readAll.forEach(map -> {
            String code = map.get("编号").toString();
            if (initMap.containsKey(code)) {

                String radm = "CF" + Test1.getPickupCode(list);

                System.out.println(
                        map.get("导入结果") + "," +
                                map.get("*人员姓名") + "," +
                                map.get("*人员邮箱") + "," +
                                radm + map.get("编号") + "," +
                                map.get("*法人公司") + "," +
                                map.get("*合同类型") + "," +
                                map.get("*期限类型") + "," +
                                map.get("合同签订日期") + "," +
                                map.get("*合同生效日期") + "," +
                                map.get("合同期限(月)") + "," +
                                map.get("合同终止日期") + "," +
                                map.get("实际终止时间") + "," +
                                map.get("签订次数") + "," +
                                map.get("试用期工资") + "," +
                                map.get("试用期满工资"));
            } else {
                System.out.println(map.get("导入结果") + "," +
                        map.get("*人员姓名") + "," +
                        map.get("*人员邮箱") + "," +
                        map.get("编号") + "," +
                        map.get("*法人公司") + "," +
                        map.get("*合同类型") + "," +
                        map.get("*期限类型") + "," +
                        map.get("合同签订日期") + "," +
                        map.get("*合同生效日期") + "," +
                        map.get("合同期限(月)") + "," +
                        map.get("合同终止日期") + "," +
                        map.get("实际终止时间") + "," +
                        map.get("签订次数") + "," +
                        map.get("试用期工资") + "," +
                        map.get("试用期满工资"));
            }

            initMap.put(code, "");

        });
    }


    private static final String SYMBOLS = "0123456789"; // 纯数字
    //如果需加入字母就改成0123456789abcdefg...........

    private static final Random RANDOM = new SecureRandom();


    /**
     * 获取长度为 6 的随机数字
     *
     * @return 随机数字
     */
    public static String getSixstr() {
        char[] nonceChars = new char[3];  //指定长度，自己可以设置

        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        return new String(nonceChars);
    }

    /**
     * 获取数组不存在的6位数取件码
     *
     * @return
     */
    private static String getPickupCode(List<String> list) {
        String sixstr = Test1.getSixstr();
        boolean contains = list.contains(sixstr);
        if (contains || sixstr.length() != 3) {
            sixstr = getPickupCode(list);
        }
        return sixstr;
    }


}